package com.qujia.label.service.impl;

import java.util.List;
import com.qujia.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.qujia.label.mapper.CustomerLabelMapper;
import com.qujia.label.domain.CustomerLabel;
import com.qujia.label.service.ICustomerLabelService;

/**
 * 用户标签Service业务层处理
 *
 * @author qujia
 * @date 2021-06-15
 */
@Service
public class CustomerLabelServiceImpl implements ICustomerLabelService
{
    @Autowired
    private CustomerLabelMapper customerLabelMapper;

    /**
     * 查询用户标签
     *
     * @param id 用户标签ID
     * @return 用户标签
     */
    @Override
    public CustomerLabel selectCustomerLabelById(Integer id)
    {
        return customerLabelMapper.selectCustomerLabelById(id);
    }

    /**
     * 查询用户标签列表
     *
     * @param customerLabel 用户标签
     * @return 用户标签
     */
    @Override
    public List<CustomerLabel> selectCustomerLabelList(CustomerLabel customerLabel)
    {
        return customerLabelMapper.selectCustomerLabelList(customerLabel);
    }

    /**
     * 新增用户标签
     *
     * @param customerLabel 用户标签
     * @return 结果
     */
    @Override
    public int insertCustomerLabel(CustomerLabel customerLabel)
    {
        customerLabel.setCreateTime(DateUtils.getNowDate());
        return customerLabelMapper.insertCustomerLabel(customerLabel);
    }

    /**
     * 修改用户标签
     *
     * @param customerLabel 用户标签
     * @return 结果
     */
    @Override
    public int updateCustomerLabel(CustomerLabel customerLabel)
    {
        customerLabel.setUpdateTime(DateUtils.getNowDate());
        return customerLabelMapper.updateCustomerLabel(customerLabel);
    }

    /**
     * 批量删除用户标签
     *
     * @param ids 需要删除的用户标签ID
     * @return 结果
     */
    @Override
    public int deleteCustomerLabelByIds(Integer[] ids)
    {
        return customerLabelMapper.deleteCustomerLabelByIds(ids);
    }

    /**
     * 删除用户标签信息
     *
     * @param id 用户标签ID
     * @return 结果
     */
    @Override
    public int deleteCustomerLabelById(Integer id)
    {
        return customerLabelMapper.deleteCustomerLabelById(id);
    }

    /**
     * 查询 标签客户信息
     * @param customerLabel
     * @return
     */
    @Override
    public List<CustomerLabel> selectNotCustomerLabelInfo(CustomerLabel customerLabel) {
        return customerLabelMapper.selectNotCustomerLabelInfo(customerLabel);
    }

    @Override
    public int editCustomerLabel(CustomerLabel customerLabel) {
        //先查询再做修改
        int i =0 ;
        CustomerLabel labelInfo =new CustomerLabel();
        labelInfo.setLabelId(customerLabel.getLabelId());
        labelInfo.setPhone(customerLabel.getPhone());
        labelInfo.setDelFlag("0");
        CustomerLabel label =customerLabelMapper.selectCustomerLabelInfo(labelInfo);
        if(label!=null&& label.getId()!=null){
            label.setDelFlag("1");
            label.setUpdateBy(customerLabel.getUpdateBy());
            label.setUpdateTime(DateUtils.getNowDate());
            i=customerLabelMapper.updateCustomerLabel(label);
        }
        return i;
    }

    /**
     * 查询本标签的客户手机号
     * @param customerLabel
     * @return
     */
    @Override
    public List<CustomerLabel> selectPhoneList(CustomerLabel customerLabel) {
        List<CustomerLabel> list= customerLabelMapper.selectPhonelist(customerLabel);
        return list;
    }
}
